package cn.edu.gzgs.mapper;

import cn.edu.gzgs.entity.Project;
import cn.edu.gzgs.vo.ProjectTreeVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.Data;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface ProjectMapper extends BaseMapper<Project> {

    // 查询项目及其名单信息
    @Select("SELECT " +
            "p.id AS projectId, " +
            "p.name AS projectName, " +
            "l.id AS listId, " +
            "l.name AS listName " +
            "FROM project p " +
            "LEFT JOIN list_meta l ON l.project_id = p.id " +
            "WHERE (l.status = 'approved' OR l.status IS NULL) " +
            "ORDER BY p.id, l.id")
    List<ProjectTreeRaw> getProjectTreeRaw();

    @Select("SELECT id, name FROM project ORDER BY id")
    List<Map<String, Object>> getAllProjects();

    // 原始数据结构
    @Data
    public static class ProjectTreeRaw {
        private String projectId;
        private String projectName;
        private String listId;
        private String listName;
    }
}